<template>
    <div class="count-card" :style="styles">
        <div v-if="src" class="count-card-icon">
            <img :src="src" />
        </div>
        <div class="count-card-content">
            <div class="title">{{ title }}</div>
            <CountUp :id-name="uid" :end-val="endVal"></CountUp>
        </div>
    </div>
</template>

<script>
import CountUp from './count-up.vue';
import { guid } from '@/libs/tools.js';
export default {
    name: 'CountCard',
    components: {
        CountUp
    },
    props: {
        src: {
            type: String,
            default: ''
        },
        title: {
            type: String,
            default: ''
        },
        value: {
            type: Number | String,
            default: null
        },
        backgroundColor: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            uid: guid()
        }
    },
    computed: {
        endVal() {
            if(!this.value) return 0;
            return Number(this.value);
        },
        styles() {
            let styles = {};
            if(this.backgroundColor) {
                styles.backgroundColor = this.backgroundColor;
            }
            return styles;
        }
    }
}
</script>

<style lang="less" scoped>
.count-card {
    display: flex;
    min-height: 90px;
    border-radius: 6px;
    background-color: #f5f5f5;
    overflow: hidden;
    &-icon {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 90px;
        height: 90px;
        img {
            display: block;
            max-width: 100%;
            max-height: 100%;
        }
    }
    &-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 10px;
        min-width: 1px;
        .title {
            font-size: 14px;
            line-height: 24px;
        }
        
    }
}
</style>